import aiTalkListInstance from '@/utils/operatorAITalk'

const baseConfig = {
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: 'http://127.0.0.1:3333'
}

class AiTalkRequest {
  static headers = {
    'Content-Type': 'application/json'
  }

  constructor(baseURL, headers) {
    this.baseURL = baseURL
    this.headers = headers
  }

  async get(url, params) {
    try {
      const response = await fetch(this.baseURL + url, {
        method: 'GET',
        headers: Object.assign({}, AiTalkRequest.headers, this.headers),
        params: params
      })
    } catch (error) {}
  }

  async post(url, data) {
    try {
      const response = await fetch(this.baseURL + url, {
        method: 'POST',
        headers: Object.assign({}, AiTalkRequest.headers, this.headers),
        body: JSON.stringify(data)
      })
      if (response.ok) {
        const ai = aiTalkListInstance()
        ai.serviceCtx(response)
      }
    } catch (error) {
      console.log('错误处理', error)
    }
  }
}

export default AiTalkRequest
